package com.trainbook.controller;


import com.trainbook.common.result.JsonResult;
import com.trainbook.entity.DTO.AddSiteDTO;
import com.trainbook.service.ISiteService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 站点表 前端控制器
 * </p>
 *
 * @author Dempsey
 * @since 2020-11-27
 */
@Controller
@RequestMapping("/site")
public class SiteController {

    @Autowired
    private ISiteService siteService;

    @GetMapping("/getAllSites")
    @ApiOperation(value = "返回所有站点", notes = "需要前端做排序")
    public JsonResult getAllSites() {
        return siteService.getAllSites();
    }

    @PostMapping("/addSite")
    @ApiOperation(value = "添加一个站点", notes = "siteB 设为相关站点的 id，siteA为新建站点的 id，由后端赋值")
    @ApiImplicitParams(value = {@ApiImplicitParam(name = "addSiteDTO", value = "新增站点的信息", dataType = "AddSiteDTO")})
    public JsonResult addSite(@RequestBody AddSiteDTO addSiteDTO) {
        return siteService.addSite(addSiteDTO);
    }

    @GetMapping("removeSite")
    @ApiOperation(value = "删除一个站点", notes = "无")
    @ApiImplicitParams(value = {@ApiImplicitParam(name = "siteId", value = "要删除的站点 id", dataType = "Integer")})
    public JsonResult removeSite(@RequestParam(value = "siteId")int siteId){
        return siteService.removeSite(siteId);
    }

}

